﻿using System;

using GL = MonoMac.OpenGL.GL;

using Storyteller.Framework.Graphics;
using Storyteller.Framework.Input;

namespace Storyteller.Framework
{
	public abstract class Game
	{
		internal static Game Instance { get; private set; }
		internal MouseState MouseState { get; private set; }
		internal bool[] KeyboardState { get; private set; }

		public int ScreenWidth { get; private set; }
		public int ScreenHeight { get; private set; }

		public Game(int screenWidth, int screenHeight)
		{
			if (Instance != null)
				throw new InvalidOperationException("Cannot instantiate multiple Game objects");

			Instance = this;

			ScreenWidth = screenWidth;
			ScreenHeight = screenHeight;
		}

		public void Clear(Color color)
		{
			GL.ClearColor(color.R, color.G, color.B, color.A);
			GL.Clear(MonoMac.OpenGL.ClearBufferMask.ColorBufferBit);
		}

		public void ChangeResolutionMac(int width, int height)
		{
			ChangeResolution(width, height);
		}

		public void LoadContentMac()
		{
			LoadContent();
		}

		public void UnloadContentMac()
		{
			UnloadContent();
		}

		public void UpdateMac(float deltaSeconds, MouseState mouseState, bool[] keyboardState)
		{
			MouseState = mouseState;
			KeyboardState = keyboardState;

			Update(deltaSeconds);
		}

		public void DrawMac()
		{
			Draw();
		}

		protected virtual void ChangeResolution(int width, int height)
		{
			ScreenWidth = width;
			ScreenHeight = height;

			GL.Viewport(0, 0, ScreenWidth, ScreenHeight);
		}

		protected virtual void LoadContent() { }
		protected virtual void UnloadContent() { }

		protected virtual void Update(float deltaSeconds) { }
		protected virtual void Draw() { }
	}
}
